<template>
    <page-decorator>
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>资格证书列表 </h5>
                        <div class="ibox-tools">
                            <a  href="/api/professional/export" class="btn btn-primary btn-xs" >
                                导出
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <el-list :stateManager="stateManager"></el-list>
                    </div>
                </div>
            </div>
        </div>
        <el-dialog :stateManager="stateManager"></el-dialog>
        <confirm-modal v-if="stateManager.deleteDialogVisible" text="你确定要删除此项内容吗？" title="删除确认"
                       v-on:cancel="stateManager.deleteDialogVisible= false"  v-on:ok="deleteModel"
        ></confirm-modal>
    </page-decorator>
</template>

<script>
  import table from './_table.vue';
  import dialog from './_dialog.vue';
  export default {
    components: {
      'el-list': table,
      'el-dialog': dialog,
    },
    data: function () {
      return {
//                departments: [{label: '综合部', value: 1}, {label: '技术部', value: 2}, {label: '行政部', value: 3}],
        stateManager: {
          refreshList: true,
          editDialogVisible: false,
          ImportDialogVisible: false,
          deleteDialogVisible: false,
          deleteModelId: 0,
          editModelId:0,
        },
        model: this.$modelDataSource({
          url: 'api/course/course',
          dataKey: 'model',
          attributes: {
            id: 0,
          }
        })
      };
    },
    created: function () {
      this.$store.commit('setTitle', '已上传资格证书列表');
    },
    methods: {
//            showEditDialog: function (id = 0) {
//                this.stateManager.editModelId = id;
//                this.stateManager.editDialogVisible = true;
//            },
      showImportDialog: function () {
        this.stateManager.ImportDialogVisible = true;
      },
      showImportSelectResultDialog:function () {
        this.stateManager.ImportSelectResultDialog = true;
      },
      deleteModel: function () {
        this.stateManager.deleteDialogVisible = false;
        let self = this;
        self.model.id = this.stateManager.deleteModelId;
        self.model.destroy(function () {
          self.model.reset();
          self.stateManager.refreshList = true;
          toastr.success('删除成功！');
        }, function () {
          if (self.model.errors.permissions_errors) {
            toastr.error(self.model.errors.permissions_errors);
          }
        });
      }
    },
  }
</script>
